-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(refactor): prefer interfaces over concrete classes #457
Conversation
This change modifies the protocol binding interfaces such as `Binding`, `Serializer` and the like to use the `CloudEventV1` interface instead of the implementation class `CloudEvent`. This should make extending the interfaces simpler as this work has grown out of efforts around the implementation of a second transport interface, Kafka. See: cloudevents#455 This commit also includes the addition of a generic type to the `Message` interface, defaulting to `string`. There is also some minor clean up involving what is exported from the `message/http` modules. Now, instead of exporting the entire implementation, only the `HTTP` binding implementation is exported, and it is then reexported by `message`. Also, a static `CloudEvent.cloneWith()` method has been added which the instance methods now use. Signed-off-by: Lance Ball <lball@redhat.com>
Also, incorporates all of the changes from cloudevents#457 Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
@@ -147,7 +147,7 @@ See: https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system`); | |||
toJSON(): Record<string, unknown> { | |||
const event = { ...this }; | |||
event.time = new Date(this.time as string).toISOString(); | |||
event.data = !isBinary(this.data) ? this.data : undefined; | |||
event.data = this.#_data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: It's not clear why we originally were unsetting the data
property in this function if it was in binary form. But I don't think we should be doing that. Making this change had no effect on the tests. Happy to discuss what the reason is for this code as it was if anyone recalls.
Signed-off-by: Lance Ball <lball@redhat.com>
This change modifies the protocol binding interfaces such as
Binding
,Serializer
and thecloneWith()
methods to use theCloudEventV1
interface instead of the implementation classCloudEvent
. This should make extending the interfaces simpler as using interfaces decouples Specification Extensions for relying on the concreteCloudEvent
class. This work has grown out of efforts around the implementation of a second transport interface, Kafka.See: #455
In addition, this PR includes:
Message
interface, defaulting tostring
message/http
modules. Now, instead of exporting the entire implementation, only theHTTP
binding implementation is exportedCloudEvent.cloneWith()
method has been added which the instance methods now useI'm pretty sure all of this is fully backwards compatible as there were no changes required for the tests.
I will hold on #455 until this has landed, so that I can pull in these changes and keep 455 small-ish.
Signed-off-by: Lance Ball lball@redhat.com